<?php
include_once dirname(__FILE__)."/common/basic.php";
include_once dirname(__FILE__)."/common/pages.class.php";
$has_logined = $func->hasLogedIn();

if($_GET[uid]){
	$uid = $_GET[uid];
}elseif($_GET[feed]){
	$uid = $func->feed_uid($_GET[feed]);
}
if(!$uid){
		$func->error("e12062003","用户不存在");
}

$user = $func->getUserById($uid);
if(!$user){
	$func->error("e12062701","用户不存在");
}

$relation = $func->getRelation($user[uid]);
if($_SESSION[uid]){
	if($uid!=$_SESSION[uid]){
		$followed = $func->has_followed($uid, $_SESSION[uid]);
	}else{
		$self = true;
	}
}

if(isset($_GET[feed])){
	$feed = $func->getFeedDetail($_GET[feed]);
	$feeds = array();
	array_push($feeds, $feed);
	$config[keyword]=$func->feeds_keywords($feeds);
	$config[desc]=$func->feeds_description($feeds);
	
	/** 设置网页标题 */
	$title = "";
	if($feed){
		if($feed[lx]=='0'){
			$title = $feed[reslist][0][name];
		}elseif($feed[lx]=='1'){
			$title = $feed[refer][reslist][0][name];
		}
	}
}else{
	$nav = $_GET[nav]?$_GET[nav]:'feeds';
	if($nav=='feeds'){
		$page = $_GET[page]?$_GET[page]:1;
		$pagesize=20;
		$total = $func->getFeedsCount($uid);
		$feeds = $func->getFeeds($user[uid],$page,$pagesize);
		$feeds_nav = $func->feeds_nav("u.php?uid=$uid&nav=feeds", $page, $pagesize, $total);
		$config[keyword]=$func->feeds_keywords($feeds);
		$config[desc]=$func->feeds_description($feeds);
}elseif($nav=='follow'){
		$page = $_GET[page];
		if(!$page){
			$page = 1;
		}
		$pagesize=20;
		$firstcount = ($page-1)*$pagesize;
		$total = $func->user_follow_count($uid);
		$persons = $func->user_follow($uid,$page,$pagesize);
		if($persons && $has_logined){
			for($i=0;$i<count($persons);$i++){
				$persons[$i][ifollowed] = $func->has_followed($persons[$i][uid], $_SESSION[uid]);
			}
		}
		pageft($total,$pagesize);
	}elseif($nav=='fans'){
		$page = $_GET[page];
		if(!$page){
			$page = 1;
		}
		$pagesize=20;
		$firstcount = ($page-1)*$pagesize;
		$total = $func->user_fans_count($uid);
		$persons = $func->user_fans($uid,$page,$pagesize);
		if($persons && $has_logined){
			for($i=0;$i<count($persons);$i++){
				$persons[$i][ifollowed] = $func->has_followed($persons[$i][uid], $_SESSION[uid]);
			}
		}
		
		pageft($total,$pagesize);
	}else{
		$func->error("e12062901","非法请求");
	}
}
$tl->set_file("u");
$tl->p();
?>